#!/usr/bin/env php
<?php

# A worker to run a query against MySQL and send the serialized
# result back. This could do more substantial work such as keep
# a local cache or process results to send less data back.

$worker= new GearmanWorker();
$worker->addServer('127.0.0.1', 4730);
$worker->addFunction('mysql', 'mysql_callback');
while (@$worker->work());

function mysql_callback($job)
{
  mysql_connect('127.0.0.1', 'root');
  $result = mysql_query($job->workload());
  $rows = array();
  while ($row = mysql_fetch_row($result))
    $rows[] = $row;
  return serialize($rows);
}

?>
